﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace syc.Store
{
    public partial class 原料磅单录入 : System.Web.UI.Page
    {
        protected string Notice = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = 0;
            if (!this.IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    int.TryParse(Request.QueryString["ID"], out id);
                }

                if (id > 0)
                {
                    this.Label_ID.Text = id.ToString();
                    this.SqlDataSource1.SelectParameters["ID"].DefaultValue = this.Label_ID.Text;
                    this.SqlDataSource1.Select(DataSourceSelectArguments.Empty);
                }
                else
                {
                    DateTime d = DateTime.Today;
                    this.Date1.Text = d.ToLongDateString();
                }
            }
        }



        protected void Button_Save_Click(object sender, EventArgs e)
        {
            string op = (string)this.Session["OperatorName"];
            if (op == null)
            {
                op = "";
            }
            if (this.Label_ID.Text == "0")
            {
                this.SqlDataSource1.InsertParameters["保管员"].DefaultValue = op;
                this.SqlDataSource1.Insert();
            }
            else
            {
                if (this.SqlDataSource1.Update() > 0)
                {
                    this.Notice = "·保存成功";
                }
            }
        }

        protected void Button_ReNew_Click(object sender, EventArgs e)
        {
            Response.Redirect("材料到货记录录入.aspx");
        }

        protected void SqlDataSource1_Selected(object sender, SqlDataSourceStatusEventArgs e)
        {
            this.LeiBie.Text = ((int)e.Command.Parameters[1].Value).ToString("D10");
            this.LeiBie.Enabled = false;
            this.GongHuo.Text = ((int)e.Command.Parameters[2].Value).ToString();

            if (!Convert.IsDBNull(e.Command.Parameters[3].Value))
            {
                this.CheHao.Text = (string)e.Command.Parameters[3].Value;
            }

            if (!Convert.IsDBNull(e.Command.Parameters[4].Value))
            {
                this.BangZhong1.Text = ((double)e.Command.Parameters[4].Value).ToString();
            }
            if (!Convert.IsDBNull(e.Command.Parameters[5].Value))
            {
                this.BangZhong2.Text = ((double)e.Command.Parameters[5].Value).ToString();
            }

            if (!Convert.IsDBNull(e.Command.Parameters[6].Value))
            {
                this.BangZhong3.Text = ((double)e.Command.Parameters[6].Value).ToString();
            }
            if (!Convert.IsDBNull(e.Command.Parameters[7].Value))
            {
                this.BangZhong4.Text = ((double)e.Command.Parameters[7].Value).ToString();
            }

            if (!Convert.IsDBNull(e.Command.Parameters[8].Value))
            {
                this.Date1.Text = ((DateTime)e.Command.Parameters[8].Value).ToLongDateString();
            }

        }

        protected void SqlDataSource1_Inserted(object sender, SqlDataSourceStatusEventArgs e)
        {
            this.Label_ID.Text = e.Command.Parameters[0].Value.ToString();
            this.Button_ReNew.Visible = true;
            this.Notice = "·保存成功";
        }
    }
}
